<script setup lang="ts">
import { nextTick, onMounted, ref } from 'vue';

defineOptions({
  name: 'Loading',
});

const emits = defineEmits(['loaded']);
const progress = ref(0);
const showProgress = ref(false);

const updateProgress = () => {
  progress.value += 0.4;
  if (progress.value >= 100) {
    progress.value = 100;
    showProgress.value = false;
    setTimeout(() => emits('loaded'), 1000);
  } else {
    requestAnimationFrame(updateProgress);
  }
};
onMounted(() => {
  nextTick(() => {
    showProgress.value = true;
    updateProgress();
  });
});

const fullScreen = () => {
  const docElm = document.documentElement;
  if (docElm.requestFullscreen) {
    docElm.requestFullscreen();
  }
};
</script>

<template>
  <div class="loading" @click="fullScreen">
    <div class="window">
      <div class="logo">
        <p class="top">Professional</p>
        <p class="mid">Web OS<span>client</span></p>
        <p class="bottom">欢迎使用</p>
      </div>
      <div class="container">
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
      </div>
    </div>
  </div>
</template>
<style scoped lang="scss">
.loading {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  background-color: #020307;

  .container {
    width: 220px;
    height: 10px;
    border: 2px solid #b2b2b2;
    border-radius: var(--radius);
    margin: 0 auto;
    padding: 2px 1px;
    overflow: hidden;
    font-size: 0;
  }

  .box {
    width: 9px;
    height: 100%;
    background: linear-gradient(
      to bottom,
      #2838c7 0%,
      #5979ef 17%,
      #869ef3 32%,
      #869ef3 45%,
      #5979ef 59%,
      #2838c7 100%
    );
    display: inline-block;
    margin-right: 2px;
    animation: loader 2s infinite;
    animation-timing-function: linear;
  }

  .logo {
    width: 220px;
    margin: 50px auto;
    margin-top: 20px;
  }

  .logo p {
    margin: 0;
    padding: 0;
  }

  .top {
    font-size: 16px;
    font-weight: 300;
    line-height: 16px;
  }

  .top:after {
    content: '\00a9';
    font-size: 10px;
    position: relative;
    top: -5px;
    margin-left: 2px;
  }

  .mid {
    font-size: 46px;
    font-weight: 700;
    line-height: 36px;
  }

  .mid span {
    font-size: 22px;
    display: inline-block;
    vertical-align: top;
    color: #ff6821;
  }

  .logo .bottom {
    font-size: 30px;
    font-weight: 300;
    line-height: 30px;
    margin-left: 5px;
  }

  @keyframes loader {
    0% {
      transform: translate(-30px);
    }

    100% {
      transform: translate(150px);
    }
  }
}
</style>
